﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YakShaver.Contract;
using System.Net.Mail;
namespace YakShaver.CodePlex
{
    [Serializable()]
    public class CodePlexNotificationService  : INotificationService
    {
        #region INotificationService Members

        private SmtpClient _smtpClient = null;
        public event EventHandler<YakShaver.Contract.WorkItemModifiedEventArgs> HandleWorkItemModifiedEvent;

        public CodePlexNotificationService(SmtpClient smtpClient)
        {
            _smtpClient = smtpClient;
        }

        public bool NotifyForIntervention(int nofityCount, IWorkItemDataContract workItem)
        {
            MailMessage message = new MailMessage("from@test.com", "to@test.com", "subject", "body");

            
            _smtpClient.Send(message);
           
            return true;
        }

        #endregion

        #region Workflow Event Raisers

        public void ModifyWorkItem(Guid instanceId, IWorkItemDataContract workItem)
        {
            EventHandler<WorkItemModifiedEventArgs> workitemEvent = this.HandleWorkItemModifiedEvent;
            if (workitemEvent != null)
                workitemEvent(null, new YakShaver.Contract.WorkItemModifiedEventArgs(instanceId, workItem));

        }

        #endregion
    }
}
